#pragma once
#include <QDialog>
#include <qbmessage/include/message_kernel.h>

class QVBoxLayout;
class ServerCombox;
class LoginProgressBtn;
class SImageButton;
class QrLoginWidget;
class SLineEdit;
class FadeTips;
class SCheckEx;
namespace qb {
    class CAuthLoginImpl;
}

class StartupDlg :
    public QDialog, public CUnknownObject<IMessageKernelObserver>
{
    friend class QrLoginWidget;
    Q_OBJECT
public:
    StartupDlg(QWidget* parent = nullptr);
    QWidget* serverList();

Q_SIGNALS:
    void notifyProgress(int, int);
protected:
    virtual void paintEvent(QPaintEvent* event) override;
    virtual void resizeEvent(QResizeEvent*) override;


    virtual void mousePressEvent(QMouseEvent* event) override;
    virtual void mouseReleaseEvent(QMouseEvent* event) override;
    virtual void mouseMoveEvent(QMouseEvent* event) override;
    virtual void keyPressEvent(QKeyEvent* event) override;

	STDMETHOD_(void, OnRecvMsg) (char* pData, int nDataLen) {}
	STDMETHOD_(void, OnRecvNetStatus) (qb::NetStatus status, short retcode);
    
protected Q_SLOTS:
    void onBtnClicked(int);
    void OnProgress(int progress, int result);//TODO error!

private:
    void updateServerList();
    void login();
    void showErrorMsg(const QString& err);
    void saveCfg();
 
private:
    QVBoxLayout* m_leftLayout = nullptr;
    ServerCombox*   m_cbServers = nullptr;
    LoginProgressBtn* m_loginBtn = nullptr;
    SImageButton* m_loginModeBtn = nullptr;
    SImageButton* m_loginSettingBtn = nullptr;
    bool          m_loginByPwd = true;
    QWidget* m_loginSettingWidget = nullptr;
    QWidget* m_scanWidget = nullptr;
    SLineEdit* m_editUser = nullptr;
    SLineEdit* m_editPwd = nullptr;
    FadeTips* m_errTips = nullptr;
    SCheckEx* m_rememberPwd = nullptr;
    SCheckEx* m_autoStart = nullptr;
    qb::CAuthLoginImpl* m_authLogin = nullptr;
    bool    m_dragging = false;
};

